﻿using System;
using System.Configuration;

namespace Xpus.Website.Configuration
{
	/// <summary>
	/// 表示配置文件中xpus/language节点下的配置。
	/// </summary>
	public class LanguageConfiguration : ConfigurationElement
	{
		/// <summary>
		/// 获取language/baseDirectory属性。
		/// </summary>
		[ConfigurationProperty("baseDirectory")]
		public string BaseDirectory
		{
			get
			{
				return (string)base["baseDirectory"];
			}
		}

		/// <summary>
		/// 获取language/defaultLanguage属性。
		/// </summary>
		[ConfigurationProperty("defaultLanguage")]
		public string DefaultLanguage
		{
			get
			{
				return (string)base["defaultLanguage"];
			}
		}

		/// <summary>
		/// 获取language/mappings属性。
		/// </summary>
		[ConfigurationProperty("mappings")]
		public LanguageMappingConfigurationCollection Mappings
		{
			get
			{
				return (LanguageMappingConfigurationCollection)base["mappings"];
			}
		}
	}

	/// <summary>
	/// 表示配置文件中xpus/language/mappings/mapping节点下的配置。
	/// </summary>
	public class LanguageMappingConfiguration : ConfigurationElement
	{
		/// <summary>
		/// 获取mapping/code属性。
		/// </summary>
		[ConfigurationProperty("code", IsRequired = true, IsKey = true)]
		public string Code
		{
			get
			{
				return (string)base["code"];
			}
		}

		/// <summary>
		/// 获取mapping/language属性。
		/// </summary>
		[ConfigurationProperty("language", IsRequired = true)]
		public string Language
		{
			get
			{
				return (string)base["language"];
			}
		}
	}

	/// <summary>
	/// 表示配置文件中xpus/language/mappings节点下的配置。
	/// </summary>
	[ConfigurationCollection(typeof(LanguageMappingConfiguration),
		AddItemName = "mapping",
		CollectionType = ConfigurationElementCollectionType.BasicMap)]
	public class LanguageMappingConfigurationCollection : ConfigurationElementCollection
	{
		/// <summary>
		/// 创建新的元素对象。
		/// </summary>
		/// <returns>新的元素对象。</returns>
		protected override ConfigurationElement CreateNewElement()
		{
			return new LanguageMappingConfiguration();
		}

		/// <summary>
		/// 获取元素的键属性。
		/// </summary>
		/// <returns>元素的键属性。</returns>
		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((LanguageMappingConfiguration)element).Code;
		}
	}
}